<?php
if(!function_exists('My_question_code_base')){
	function My_question_code_base(){
		return [
			'num' => 1000000000,
			'dict' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		];
	}
}
/**
 * @author	zhe.wang
 * @desc		int from 10进制ID to 62进制编码
 */
if(!function_exists('My_question_code_fromid')){
	function My_question_code_fromid($num){
		$base = My_question_code_base();
		$num = $base['num']+ $num;
		$to = 62;
		$code = '';
		do {
			$code = $base['dict'][bcmod($num, $to)] . $code;
			$num = bcdiv($num, $to);
		}while($num > 0);
		return $code;
	}
}
/**
 * @author	zhe.wang
 * @desc		str from 62进制编码 to 10进制ID
 */
if(!function_exists('My_question_code_toid')){
	function My_question_code_toid($code){
		$base = My_question_code_base();
		$len = strlen($code);
		$dec = 0;
		$from = 62;
		for($i = 0;$i<$len;$i++){
			//找到对应字典的下标
			$pos = strpos($base['dict'], $code[$i]);
			$dec += $pos * pow($from, $len - $i - 1);
		}
		return $dec ? $dec - $base['num'] : 0;
	}
}